/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

// This is an example of a class exported from the 数据工具库.lib
class C数据工具库
{
public:
    C数据工具库();
    // TODO: add your methods here.
};

// This is an example of an exported variable
extern int n数据工具库;

// This is an example of an exported function.
int fn数据工具库(void);


#include <基本类型.h>
#include <vector>
#include <set>


template<typename T>
std::vector<T> f_DT_末尾删除法移除数据(T* 原数据, uint32& 末尾ID, uint32* 要删除的数据ID, uint32 num) {
	std::vector<T> 删除数据(num);
	auto* data = 删除数据.data();

	for (uint32 i = 0; i < num; ++i) {
		--末尾ID;
		uint32 del_id = 要删除的数据ID[i]; 

		bool 是否交换 = true;
		//当前删除数据是否就在末尾
		for (uint32 j = 0; j < num; ++j) {
			if (末尾ID == 要删除的数据ID[j]) {
				是否交换 = false;
				break;
			}
		}

		data[i] = 原数据[del_id];
		if (是否交换) {
			原数据[del_id] = 原数据[末尾ID];
		}
	}
	return 删除数据;
}



template<typename T>
void f_DT_末尾删除法移除数据组(T* 原数据, uint64& 末尾ID, uint32* id, uint64 num, uint64 group) {
	for (uint64 i = 0; i < num; ++i) {
		--末尾ID;
		uint32 cid = id[i];

		bool 是否交换 = true;
		for (uint32 j = 0; j < num; ++j) {
			if (末尾ID == id[j]) {
				是否交换 = false;
				break;
			}
		}

		if (是否交换) {
			for (uint32 k = 0; k < group; ++k) {
				原数据[cid * group + k] = 原数据[末尾ID * group + k];
			}
		}
	}
}



template<typename F>
void f_DT_末尾删除法移除数据_fun(uint32& 末尾ID, uint32* id, uint32 num, F const & f) {
	for (uint32 i = 0; i < num; ++i) {
		--末尾ID;

		uint32 原数据ID = id[i];

		bool 是否交换 = true;
		for (uint32 j = 0; j < num; ++j) {
			if (末尾ID == id[j]) {
				是否交换 = false;
				break;
			}
		}
		//data[i] = 原数据[原数据ID];
		if (是否交换) {
			//原数据[原数据ID] = 原数据[末尾ID];
			f(原数据ID, 末尾ID);
		}
	}
}



class C_Key分配器 {
	std::vector<uint32> m_回收站;
	//std::set<uint32> m_Key;
	uint32 m_末尾;
public:
	C_Key分配器();

	uint32 f_Gen();
	void f_Move(uint32 key);
	void f_Clear();
};



class C_StrKey分配器 {
	std::set<std::wstring> m_Key;
	//std::set<std::wstring> m_回收站;
	//std::set<uint32> m_Key;
	uint32 m_末尾;
public:
	C_StrKey分配器();

	std::wstring f_Gen(std::wstring 前缀);
	void f_Move(std::wstring key);
	void f_Clear();
};








